package com.servicesystem.servicesystem.controller.douyin;

import com.servicesystem.servicesystem.entity.douyin.GoodsLib;
import com.servicesystem.servicesystem.entity.douyin.vo.goodsLib.GoodsLibVO;
import com.servicesystem.servicesystem.service.GoodsLibService;
import com.servicesystem.servicesystem.untis.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @author X
 * @version 1.0
 * @ClassName GoodsLibController
 * @description
 * @date 2020/9/12
 **/
@RestController
@RequestMapping("/douyin/goods/lib")
public class GoodsLibController {

    @Autowired
    private GoodsLibService goodsLibService;

    /***
     * 获取1688商品列表
     * @return
     */
   /* @GetMapping("/getGoodsLib")
    public R getGoodsLib() {
        List<GoodsLibVO> goodsLib = goodsLibService.getGoodsLib();
        return R.success(goodsLib);
    }*/
    @GetMapping("/getGoodsLib")
    public R getGoodsLib() {
        List<GoodsLib> goodsLib = goodsLibService.getGoodsLib();
        ArrayList<String> strings = new ArrayList<>();
        for (GoodsLib lib : goodsLib) {
            String productId = lib.getProductId();
            strings.add(productId);
        }
        return R.success(goodsLib);
    }

    @GetMapping("/getGoodsLibProductId/{id}")
    public R getGoodsLibProductId(@PathVariable(value = "id")String id) {
       String productId = goodsLibService.getGoodsLibProductId(id);
        return R.success(productId);
    }

    /***
     * 通过id查询商品数据
     * @param id
     * @return
     * @throws Exception
     */
    @GetMapping("/getGoodsInfoById/{id}")
    public R getGoodsInfoById(@PathVariable(value = "id") String id) throws Exception {
        GoodsLib result = goodsLibService.getGoodsInfoById(id);
        return R.success(result);
    }
}
